﻿using BaseUI;
using BLL;
using System;
using System.Data;

namespace Thksoft.Module.ParameterSettings
{
    public partial class AnnouncementMore : BasePage
    {
        private SYS_ANNOUNCEMENTBLL announbll = new SYS_ANNOUNCEMENTBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            string InerHtmls = " <div ><ul>";
            //查询待办信息
            var startTime = " TO_DATE('" + System.DateTime.Now.ToString() + "','YYYY-MM-DD HH24:MI:SS')";
            DataTable temp = announbll.GetNotice(startTime, CurrentUserCompanyID.ToString());
            if (temp != null)
            {
                Label1.Text = temp.Rows.Count.ToString();
            }

            #region 公告

            if (temp != null && temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    string str = "【" + temp.Rows[i]["C_NAME"].ToString() + "】'" + temp.Rows[i]["C_CONTENT"].ToString() + "' " + Convert.ToDateTime(temp.Rows[i]["D_STARTTIME"]).ToString("yyyy-MM-dd HH:mm:ss");

                    str = SubStr(str);
                    InerHtmls += "<li><span>" + Convert.ToDateTime(temp.Rows[i]["D_STARTTIME"]).ToString("[MM-dd]") + "</span><a href='#' onclick=\"achlick('" + temp.Rows[i]["N_ID"] + "');\">" + str;

                    DateTime time = Convert.ToDateTime(temp.Rows[i]["D_STARTTIME"]).AddDays(10);//10天以内的有图标
                    DateTime now = DateTime.Now;
                    if (time >= now)
                    {
                        InerHtmls += "<img src='/Images/main_right/new.gif'/> ";
                    }
                    InerHtmls += "</a></li>";
                }
            }

            #endregion 公告

            InerHtmls += "</ul></div> ";
            div1.InnerHtml = InerHtmls;
        }

        /// <summary>
        /// 截取前30字符
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private string SubStr(string str)
        {
            if (str.Length > 50)
            {
                str = str.Substring(0, 50) + "...";
            }
            return str;
        }
    }
}